<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .success{
            color: green;
        }
        .error{
            color: red;
        }
        .loading{
            color: transparent;
        }
        .loading::before{
            display: inline-block;
            content: "";
            background-image: url(./img/loading.gif);
            width: 20px;
            height: 20px;
            background-size: 100%;
            vertical-align: middle;
        }
    </style>
    <script src="./js/vue.js"></script>
    <script src="./js/jquery-1.9.0.js"></script>
</head>
<body>
    <div id="app">
        <div class="box">
            <label for="loginName">登陆名:</label>
            <input type="text" id="loginName" v-model.lazy="loginName">
            <span :class="stateClass">{{ msg }}</span>
        </div>
        <input type="text" name="" id=""><br>
        <input type="text" name="" id=""><br>
        <input type="text" name="" id=""><br>
        <input type="text" name="" id=""><br>

    </div>
</body>
<script>
    new Vue({
        el:"#app",
        data:{
            loginName:"",
            msg:"",
            stateClass:""
        },
        watch:{
            loginName(nv){
                this.stateClass = "loading";
                $.ajax({
                    url:"http://127.0.0.1/checkLoginName.php",
                    method:"post",
                    data:{
                        loginName:nv
                    },
                    dataType:"json",
                    success:(data)=>{
                        console.log(data);
                        this.msg = data.msg;
                        this.stateClass = data.success?"success":"error";
                    },
                    error:()=>{
                        this.msg = "请求超时" 
                        this.stateClass = "error";

                    }
                })
            }
        }
        
    })
</script>
</html>